<%@ page contentType="image/jpeg;charset=UTF-8" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %>

<%
//设置页面不缓存
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);

ActivitiServiceImpl activitiService = (ActivitiServiceImpl) ServiceFinder.getContext(request).getBean("activitiService");
RepositoryService repositoryService = activitiService.getRepositoryService();
ProcessDefinition processDef=repositoryService.createProcessDefinitionQuery().deploymentId(processId).
orderByProcessDefinitionVersion().desc().singleResult();
ProcessInstance processInstance=activitiService.getRuntimeService().startProcessInstanceById(processDef.getId());
ProcessDefinitionEntity pde = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDef.getId());
activitiService.getRuntimeService().getActiveActivityIds(processInstance.getId());
if(pde!=null){
InputStream imageStream=ProcessDiagramGenerator.generateDiagram(pde, "png", activitiService.getRuntimeService().getActiveActivityIds(processInstance.getId()));
//InputStream imageStream=ProcessDiagramGenerator.generatePngDiagram(pde);

BufferedInputStream input = null;
BufferedOutputStream output = null;

try {
// Open streams.
input = new BufferedInputStream(imageStream );
output = new BufferedOutputStream(response.getOutputStream() );

// Write file contents to response.
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}

} finally {
// Gently close streams.
close(output);
close(input);
}


// 输出图象到页面
ImageIO.write(image, "JPEG", response.getOutputStream());

out.clear();
out = pageContext.pushBody();
%>